<html><head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8"><title>OpenGLGadget.pb</title></head>
<body bgcolor="#FFFFDF" link="#009999" vlink="#006666" alink="#006666">
<pre><font face="Courier New, Courier, mono"size="2"><font color="#006666">;
</font><font color="#006666">; OpenGL Gadget demonstration
</font><font color="#006666">;
</font><font color="#006666">; (c) Fantaisie Software
</font><font color="#006666">;
</font><font color="#006666">; Axis explainations:
</font><font color="#006666">;
</font><font color="#006666">;             +
</font><font color="#006666">;             y
</font><font color="#006666">;
</font><font color="#006666">;             |
</font><font color="#006666">;             |
</font><font color="#006666">;  +          |
</font><font color="#006666">;  x ---------\
</font><font color="#006666">;              \
</font><font color="#006666">;               \
</font><font color="#006666">;                \ 
</font><font color="#006666">;                  z+
</font><font color="#006666">;
</font><font color="#006666">; So a rotate on the y axis will take the y axis as center. With OpenGL, we can specify
</font><font color="#006666">; positive And negative value. Positive values are always in the same sens as the axis
</font><font color="#006666">; (like described on the schmatic, with '+' signs)
</font><font color="#006666">;
</font>
<b><font color="#006666">Global</font></b> RollAxisX.f
<b><font color="#006666">Global</font></b> RollAxisY.f
<b><font color="#006666">Global</font></b> RollAxisZ.f

<b><font color="#006666">Global</font></b> RotateSpeedX.f = 1.0
<b><font color="#006666">Global</font></b> RotateSpeedY.f
<b><font color="#006666">Global</font></b> RotateSpeedZ.f = 1.0

<b><font color="#006666">Global</font></b> ZoomFactor.f = 1.0 <font color="#006666">; Distance of the camera. Negative value = zoom back
</font>
<b><font color="#006666">Procedure</font></b> <font color="#006666">DrawCube</font>(Gadget)
<font color="#006666">  SetGadgetAttribute</font>(Gadget, <font color="#924B72">#PB_OpenGL_SetContext</font>, <font color="#924B72">#True</font>)
  
<font color="#006666">  glPushMatrix_</font>()                  <font color="#006666">; Save the original Matrix coordinates
</font><font color="#006666">  glMatrixMode_</font>(<font color="#924B72">#GL_MODELVIEW</font>)

<font color="#006666">  glTranslatef_</font>(0, 0, ZoomFactor)  <font color="#006666">;  move it forward a bit
</font>
<font color="#006666">  glRotatef_ </font>(RollAxisX, 1.0, 0, 0) <font color="#006666">; rotate around X axis
</font><font color="#006666">  glRotatef_ </font>(RollAxisY, 0, 1.0, 0) <font color="#006666">; rotate around Y axis
</font><font color="#006666">  glRotatef_ </font>(RollAxisZ, 0, 0, 1.0) <font color="#006666">; rotate around Z axis
</font> 
  RollAxisX + RotateSpeedX 
  RollAxisY + RotateSpeedY 
  RollAxisZ + RotateSpeedZ 

  <font color="#006666">; clear framebuffer And depth-buffer
</font>
<font color="#006666">  glClear_ </font>(<font color="#924B72">#GL_COLOR_BUFFER_BIT</font> | <font color="#924B72">#GL_DEPTH_BUFFER_BIT</font>)

  <font color="#006666">; draw the faces of a cube
</font>  
  <font color="#006666">; draw colored faces
</font>
<font color="#006666">  glDisable_</font>(<font color="#924B72">#GL_LIGHTING</font>)
<font color="#006666">  glBegin_  </font>(<font color="#924B72">#GL_QUADS</font>)
  
  <font color="#006666">; Build a face, composed of 4 vertex !</font>  <font color="#006666">; glBegin() specify how the vertexes are considered. Here a group of
</font>  <font color="#006666">; 4 vertexes (GL_QUADS) form a rectangular surface.
</font>
  <font color="#006666">; Now, the color stuff: It's r,v,b but with float values which
</font>  <font color="#006666">; can go from 0.0 To 1.0 (0 is .. zero And 1.0 is full intensity) 
</font>  
<font color="#006666">  glNormal3f_ </font>(0,0,1.0)
<font color="#006666">  glColor3f_  </font>(0,0,1.0)
<font color="#006666">  glVertex3f_ </font>(0.5,0.5,0.5)   
<font color="#006666">  glColor3f_  </font>(0,1.0,1.0)         
<font color="#006666">  glVertex3f_ </font>(-0.5,0.5,0.5)
<font color="#006666">  glColor3f_  </font>(1.0,1.0,1.0)
<font color="#006666">  glVertex3f_ </font>(-0.5,-0.5,0.5)
<font color="#006666">  glColor3f_  </font>(0,0,0)
<font color="#006666">  glVertex3f_ </font>(0.5,-0.5,0.5) 

  <font color="#006666">; The other face is the same than the previous one 
</font>  <font color="#006666">; except the colour which is nice blue To white gradiant
</font>
<font color="#006666">  glNormal3f_ </font>(0,0,-1.0)
<font color="#006666">  glColor3f_  </font>(0,0,1.0)
<font color="#006666">  glVertex3f_ </font>(-0.5,-0.5,-0.5)
<font color="#006666">  glColor3f_  </font>(0,0,1.0)
<font color="#006666">  glVertex3f_ </font>(-0.5,0.5,-0.5)
<font color="#006666">  glColor3f_  </font>(1.0,1.0,1.0)
<font color="#006666">  glVertex3f_ </font>(0.5,0.5,-0.5)
<font color="#006666">  glColor3f_  </font>(1.0,1.0,1.0)
<font color="#006666">  glVertex3f_ </font>(0.5,-0.5,-0.5)
  
<font color="#006666">  glEnd_</font>()
  
  <font color="#006666">; draw shaded faces
</font>
<font color="#006666">  glEnable_</font>(<font color="#924B72">#GL_LIGHTING</font>)
<font color="#006666">  glEnable_</font>(<font color="#924B72">#GL_LIGHT0</font>)
<font color="#006666">  glBegin_ </font>(<font color="#924B72">#GL_QUADS</font>)

<font color="#006666">  glNormal3f_ </font>(   0, 1.0,   0)
<font color="#006666">  glVertex3f_ </font>( 0.5, 0.5, 0.5)
<font color="#006666">  glVertex3f_ </font>( 0.5, 0.5,-0.5)
<font color="#006666">  glVertex3f_ </font>(-0.5, 0.5,-0.5)
<font color="#006666">  glVertex3f_ </font>(-0.5, 0.5, 0.5)

<font color="#006666">  glNormal3f_ </font>(0,-1.0,0)
<font color="#006666">  glVertex3f_ </font>(-0.5,-0.5,-0.5)
<font color="#006666">  glVertex3f_ </font>(0.5,-0.5,-0.5)
<font color="#006666">  glVertex3f_ </font>(0.5,-0.5,0.5)
<font color="#006666">  glVertex3f_ </font>(-0.5,-0.5,0.5)

<font color="#006666">  glNormal3f_ </font>(1.0,0,0)
<font color="#006666">  glVertex3f_ </font>(0.5,0.5,0.5)
<font color="#006666">  glVertex3f_ </font>(0.5,-0.5,0.5)
<font color="#006666">  glVertex3f_ </font>(0.5,-0.5,-0.5)
<font color="#006666">  glVertex3f_ </font>(0.5,0.5,-0.5)

<font color="#006666">  glNormal3f_ </font>(-1.0,   0,   0)
<font color="#006666">  glVertex3f_ </font>(-0.5,-0.5,-0.5)
<font color="#006666">  glVertex3f_ </font>(-0.5,-0.5, 0.5)
<font color="#006666">  glVertex3f_ </font>(-0.5, 0.5, 0.5)
<font color="#006666">  glVertex3f_ </font>(-0.5, 0.5,-0.5)

<font color="#006666">  glEnd_</font>()

<font color="#006666">  glPopMatrix_</font>()
<font color="#006666">  glFinish_</font>()

<font color="#006666">  SetGadgetAttribute</font>(Gadget, <font color="#924B72">#PB_OpenGL_FlipBuffers</font>, <font color="#924B72">#True</font>)
<b><font color="#006666">EndProcedure</font></b>


<b><font color="#006666">Procedure</font></b> <font color="#006666">SetupGL</font>()
    
<font color="#006666">  glMatrixMode_</font>(<font color="#924B72">#GL_PROJECTION</font>)
<font color="#006666">  gluPerspective_</font>(30.0, 200/200, 1.0, 10.0) 
  
  <font color="#006666">; position viewer
</font><font color="#006666">  glMatrixMode_</font>(<font color="#924B72">#GL_MODELVIEW</font>)
  
<font color="#006666">  glTranslatef_</font>(0, 0, -5.0)
  
<font color="#006666">  glEnable_</font>(<font color="#924B72">#GL_DEPTH_TEST</font>)   <font color="#006666">; Enabled, it slowdown a lot the rendering. It's to be sure than the
</font>                              <font color="#006666">; rendered objects are inside the z-buffer.
</font>  
<font color="#006666">  glEnable_</font>(<font color="#924B72">#GL_CULL_FACE</font>)    <font color="#006666">; This will enhance the rendering speed as all the back face will be
</font>                              <font color="#006666">; ignored. This works only with CLOSED objects like a cube... Singles
</font>                              <font color="#006666">; planes surfaces will be visibles only on one side.
</font>    
<font color="#006666">  glShadeModel_</font>(<font color="#924B72">#GL_SMOOTH</font>)
<b><font color="#006666">EndProcedure</font></b>


<b><font color="#006666">Procedure</font></b> <font color="#006666">HandleError </font>(Result, Text$)
  <b><font color="#006666">If</font></b> Result = 0
<font color="#006666">    MessageRequester</font>("Error", Text$, 0)
    <b><font color="#006666">End</font></b>
  <b><font color="#006666">EndIf</font></b>
<b><font color="#006666">EndProcedure</font></b>

<font color="#006666">OpenWindow</font>(0, 0, 0, 530, 320, "OpenGL Gadget", <font color="#924B72">#PB_Window_SystemMenu</font> | <font color="#924B72">#PB_Window_ScreenCentered</font>)

<font color="#006666">OpenGLGadget</font>(0, 10, 10, 200, 200)
<font color="#006666">SetupGL</font>()

<font color="#006666">OpenGLGadget</font>(1, 220, 10, 300, 300)
<font color="#006666">SetupGL</font>()

<font color="#006666">AddWindowTimer</font>(0, 1, 16) <font color="#006666">; about 60 fps
</font>
<b><font color="#006666">Repeat</font></b>
  Event =<font color="#006666"> WaitWindowEvent</font>()
  
  <b><font color="#006666">Select</font></b> Event
    <b><font color="#006666">Case</font></b> <font color="#924B72">#PB_Event_Timer</font>
      <b><font color="#006666">If</font></b> <font color="#006666">EventTimer</font>() = 1
<font color="#006666">        DrawCube</font>(0)
<font color="#006666">        DrawCube</font>(1)
      <b><font color="#006666">EndIf</font></b>
  <b><font color="#006666">EndSelect</font></b>
  
<b><font color="#006666">Until</font></b> Event = <font color="#924B72">#PB_Event_CloseWindow</font>
</font></pre>
</body></html>
